/**
 * Role entity. Getters & setters.
 */
package com.xoomworks.rsfr.model;

import java.io.Serializable;
import java.util.Set;

/**
 * The persistent class for the roles database table.
 * @author andrea.ghisa
 */
public class Role extends BaseEntity implements Serializable {
    /**
     * Super admin id.
     */
    public static final long S_ADMIN = 1000L;
    /**
     * Company admin id.
     */
    public static final long C_ADMIN = 2000L;
    /**
     * Copmany user id.
     */
    public static final long C_USER = 3000L;

    private static final long serialVersionUID = 1L;

    private String roleName;

    // uni-directional many-to-many association to Operation
    private Set<Operation> operations;

    /**
     * Constructor with no fields.
     */
    public Role() {
    }

    /**
     * Constructor with specified parameters.
     * @param roleName
     *            String Represents the role name of the resource.
     * @param operations
     *            Operations Represents a list of operations which resources
     *            have access.
     */
    public Role(final String roleName, final Set<Operation> operations) {
        super();
        this.roleName = roleName;
        this.operations = operations;
    }

    /**
     * Gets the role name of the resource.
     * @return roleName String Represents the role name of the resource.
     */
    public String getRoleName() {
        return this.roleName;
    }

    /**
     * Sets the role name of the resource.
     * @param roleName
     *            String Which is used to set the roleName.
     */
    public void setRoleName(final String roleName) {
        this.roleName = roleName;
    }

    /**
     * Gets a list of operations which resources have access.
     * @return operations Set<Operations> Represents a list of operations which
     *         resources have access.
     */
    public Set<Operation> getOperations() {
        return this.operations;
    }

    /**
     * Sets a list of operations which resources have access.
     * @param operations
     *            St<Operation> Which is used to set the operations.
     */
    public void setOperations(final Set<Operation> operations) {
        this.operations = operations;
    }

    /**
     * Is used to add an operation to user.
     * @param operation
     *            Operation Represents an operation which a user can use.
     */
    public void addOperation(final Operation operation) {
        operations.add(operation);
    }

    /**
     * Is used to delete an operation to user.
     * @param operation
     *            Operation
     */
    public void deleteOperation(final Operation operation) {
        operations.remove(operation);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = (prime * result) + ((roleName == null) ? 0 : roleName.hashCode());
        return result;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Role other = (Role) obj;
        if (roleName == null) {
            if (other.roleName != null) {
                return false;
            }
        } else if (!roleName.equals(other.roleName)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Role [roleName=" + roleName + ", operations=" + operations + "]";
    }


}
